home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / frntsdk1.cpt / Frontier SDK 1.0 ƒ / Applet Toolkit / bitmaps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-21  |  2.2 KB  |  116 lines

  1.  
  2. /*⌐ Copyright 1988-1991 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. /*
  6. bitmaps.c -- routines which manage off-screen bitmaps.  In order to use these routines
  7. the program must call "initbitmaps" before calling anything.
  8.  
  9. initbitmaps takes a boolean.  if false, then all subsequent calls to bitmap routines do
  10. nothing but return.
  11. */
  12.  
  13. #include "appletinternal.h"
  14. #include "bitmaps.h"
  15.  
  16.  
  17. BitMap offscreenbitmap, savedbitmap;
  18.  
  19. Handle bitmapbasehandle;
  20.  
  21. boolean flbitmapsenabled;
  22.  
  23. boolean flbitmapopen = false; /*is one open right now?*/
  24.  
  25.  
  26.  
  27. boolean openbitmap (r, w) Rect r; WindowPtr w; {
  28.  
  29.     register short nrowbytes;
  30.     register long nboxbytes;
  31.     register long sizehandle;
  32.     
  33.     flbitmapopen = false;
  34.     
  35.     if (!flbitmapsenabled) /*application doesn't want any bitmaps*/
  36.         return (false);
  37.     
  38.        nrowbytes = (r.right - r.left + 7) / 8;
  39.        
  40.        if ((nrowbytes % 2) == 1) /*odd number*/
  41.           nrowbytes++;
  42.       
  43.     nboxbytes = (r.bottom - r.top) * nrowbytes;
  44.    
  45.     SetHandleSize (bitmapbasehandle, nboxbytes);
  46.  
  47.     sizehandle = GetHandleSize (bitmapbasehandle);
  48.  
  49.     if (sizehandle < nboxbytes) {
  50.     
  51.          SetHandleSize (bitmapbasehandle, 10L);
  52.  
  53.           return (false);
  54.           }
  55.  
  56.     HLock (bitmapbasehandle);
  57.  
  58.     offscreenbitmap.baseAddr = *bitmapbasehandle;
  59.  
  60.     offscreenbitmap.rowBytes = nrowbytes;
  61.  
  62.     offscreenbitmap.bounds = r;
  63.  
  64.     savedbitmap = (*w).portBits;
  65.  
  66.     CopyBits (&savedbitmap, &offscreenbitmap, &r, &r, srcCopy, nil);
  67.     
  68.     SetPortBits (&offscreenbitmap);
  69.     
  70.     flbitmapopen = true; /*remember in our own local global*/
  71.  
  72.     return (true);
  73.     } /*openbitmap*/
  74.  
  75.  
  76. void closebitmap (w) WindowPtr w; {
  77.  
  78.     if (flbitmapsenabled && flbitmapopen) {
  79.         
  80.         flbitmapopen = false;
  81.         
  82.         SetPortBits (&savedbitmap);
  83.     
  84.         CopyBits (
  85.                &offscreenbitmap, &((*w).portBits), &offscreenbitmap.bounds, 
  86.            
  87.                &offscreenbitmap.bounds, srcCopy, nil);
  88.        
  89.         HUnlock (bitmapbasehandle);
  90.        
  91.           offscreenbitmap.baseAddr = 0;
  92.           
  93.         SetHandleSize (bitmapbasehandle, 10L);
  94.         }
  95.     } /*closebitmap*/
  96.  
  97.     
  98. void initbitmaps (boolean flbitmaps) {
  99.  
  100.     flbitmapsenabled = flbitmaps;
  101.     
  102.     if (flbitmapsenabled) {
  103.     
  104.           bitmapbasehandle = NewHandle (10L); 
  105.           
  106.           offscreenbitmap.baseAddr = 0;
  107.           
  108.           offscreenbitmap.rowBytes = 2;
  109.           
  110.           SetRect (&offscreenbitmap.bounds, 0, 0, 0, 0);
  111.           }
  112.     } /*initbitmaps*/
  113.     
  114.  
  115.  
  116.